<?php

/* *
 * 资讯
 */
namespace Common\Model;
use Think\Model;
class StorageModel extends BaseModel {

    public function queryForList($page=null, $map=null) {
        $list = $this->alias("sr")
            ->join("left join __ADMIN__ emp on emp.employee_id = sr.update_id")
            ->join("left join __STORE__ s on s.store_id = sr.store_id")
            ->join("left join __SUPPLIER__ sl on sl.supplier_id = sr.supplier_id")
            ->join("left join __CODE__ c on c.code_id = sr.code_id")
            ->join("left join __CODE__ p on p.code_id = c.parentid")
            ->join("left join __MATERIAL__ m on m.code_id = sr.code_id")
            ->join("left join __FINISHED_PRODUCT__ fp on fp.finished_product_id = sr.finished_product_id")
            ->join("left join __CLASS__ cl on cl.class_id = fp.class_id")
            ->join("left join __INSTORE__ isr on isr.instore_id = sr.instore_id")
            ->join("left join __CUSTOMIZED_PRODUCT__ cp on cp.customized_product_id = isr.code_id")
            ->join("left join __WORKORDER__ wo on wo.workorder_id = isr.product_id")
            ->where(getWhereSqlByMap($map))
            ->order("sr.update_time desc")
            ->limit($page->firstRow . ',' . $page->listRows)
            ->field("sr.*, emp.admin_name, s.store_name, sl.supplier_name, c.name as code_name, p.name as parent_name, c.full_name, m.material_name, m.spec, m.prop, m.unit as material_unit, m.barcode as material_barcode, fp.name as finished_product_name, fp.number as finished_product_code, fp.barcode as finished_product_barcode, fp.unit as finished_product_unit, cl.class_name, isr.inventory_name, isr.spec as instore_spec, isr.unit as instore_unit, isr.barcode as instore_barcode, cp.customized_product_code, wo.batch_no as instore_batch_no, wo.price as instore_price")
            ->select();

        return $list;

    }

    public function getListCount($map = null) {

        $count = $this->alias("sr")
//            ->join("left join __PRODUCT__ p on p.product_id = wo.product_id")
//            ->join("left join __CUSTOMER__ cus on cus.customer_id = wo.customer_id")
            ->where(getWhereSqlByMap($map))
            ->count();

        return $count;
    }

}

